#ifndef __TIMESTAMP_H__
#define __TIMESTAMP_H__
#include <iostream>
#include <string>
#include <time.h>

using std::string;

class TimeStamp
{
public:
    TimeStamp();
    explicit TimeStamp(int64_t microSecondsSinceEpochArg);
    static TimeStamp now();
    string toString() const;
    std::string toFormattedString(bool showMicroseconds = true) const;
    // 有效性判断
    bool isValid() const { return _microSecondsSinceEpoch > 0; }

    // 获取微秒数
    int64_t microSecondsSinceEpoch() const { return _microSecondsSinceEpoch; }
    // 时间常量
    static const int kMicroSecondsPerSecond = 1000 * 1000;

private:
    int64_t _microSecondsSinceEpoch; // 微秒数
};
inline bool operator<(TimeStamp lhs, TimeStamp rhs)
{
    return lhs.microSecondsSinceEpoch() < rhs.microSecondsSinceEpoch();
}

inline bool operator==(TimeStamp lhs, TimeStamp rhs)
{
    return lhs.microSecondsSinceEpoch() == rhs.microSecondsSinceEpoch();
}

#endif